<?php
declare(strict_types=1);
namespace SixShop\WechatPay\Service;

use GuzzleHttp\Promise\PromiseInterface;
use SixShop\Wechat\Facade\WechatUser;
use SixShop\WechatPay\Config;
use SixShop\WechatPay\Enum\TransferBillStatusEnum;
use SixShop\WechatPay\Model\WechatpayTransferBillModel;
use SixShop\WechatPay\Trait\HandleAsyncRequestTrait;
use WeChatPay\BuilderChainable;
use WeChatPay\Crypto\Rsa;

class WechatpayTransferBillService
{
    public function __construct(private Config $config)
    {
    }

    public function apply(int $userID, float $transferAmount, string $userName, float $fee): int
    {
        return WechatpayTransferBillModel::create([
            'user_id' => $userID,
            'mch_id' => $this->config->mchid,
            'appid' => $this->config->appid,
            'transfer_amount' => bcmul((string)$transferAmount, '100', 0),
            'fee' => bcmul((string)$fee, '100', 0),
            'openid' => WechatUser::openid($userID),
            'user_name' => $userName,
            'state' => TransferBillStatusEnum::APPLYING,
            'transfer_remark' => '提现',
        ])->id;
    }
}